<?php
 	require '../tools.func.php';
 	require '../db.func.php';
 	require  'auth.php';
	require 'head.php';
	
	$id=$_GET['id'];
	$prefix=getprefix();
	$sql="SELECT name,code,price,description,stock FROM {$prefix}product WHERE id={$id} ";
	$res=queryone($sql);

	if(!empty($_POST['name'])){
		$prefix=getprefix();
		 $name=htmlentities($_POST['name']);
		 $code=htmlentities($_POST['code']);
		 $price=htmlentities($_POST['price']);
		 $description=htmlentities($_POST['description']);
		 $stock=htmlentities($_POST['stock']);
		 $sq="UPDATE {$prefix}product SET name='$name',code='$code',price='$price',description='$description' ,stock='$stock' WHERE id='{$id}' ";
		 execute($sq);
		 $res=queryone($sql);
		 setinfo('修改成功');
		
	}
?>
				<div class="row">
					<div class="col-md-12">
						<div class="card">
							<div class="card-header card-header-primary">
								<h4 class="card-title">添加商品</h4>
								<p class="card-category">添加一个商品</p>
							</div>
							<div class="card-body">
								<?php if(hasinfo()) echo getinfo();?>
								<form action="product_edit.php?id=<?php echo $id;?>" method="post">
									<div class="row">
										<div class="col-md-6">
											<div class="form-group">
												<label class="bmd-label-floating">商品名称</label>
												<input type="text" value="<?php echo $res['name'];?>" class="form-control" name="name" >
											</div>
										</div>
										<div class="col-md-6">
											<div class="form-group">
												<label class="bmd-label-floating">商品单价</label>
												<input type="number" value="<?php echo $res['price'];?>" class="form-control" name="price">
											</div>
										</div>
									</div>
									<div class="row">
										<div class="col-md-6">
											<div class="form-group">
												<label class="bmd-label-floating">商品库存</label>
												<input type="number" value="<?php echo $res['stock'];?>" class="form-control"
												name="stock">
											</div>
										</div>
										<div class="col-md-6">
											<div class="form-group">
												<label class="bmd-label-floating">商品编号</label>
												<input type="text" value="<?php echo $res['code'];?>" class="form-control" name="code">
											</div>
										</div>
									</div>
									<div class="row">
										<div class="col-md-12">
											<div class="form-group">
												<label>商品描述</label>
												<div class="form-group bmd-form-group">
													<textarea id="description" class="form-control" rows="5" name="description"><?php echo $res['description']?></textarea>
												</div>
											</div>
										</div>
									</div>
									<button type="submit" class="btn btn-primary pull-right">修改商品</button>
									<div class="clearfix"></div>
								</form>
							</div>
						</div>
					</div>

				</div>
	<?php
		require 'foot.php';
	?>